<?php
class Model_LibraryAcl extends Zend_Acl {
    public function __construct() {
        $this->addRole(new Zend_Acl_Role('guests'));
        $this->addRole(new Zend_Acl_Role('users'), 'guests');
        $this->addRole(new Zend_Acl_Role('admins'), 'users');
        
        $this->add(new Zend_Acl_Resource('library'))
        		->add(new Zend_Acl_Resource('library:books'), 'library')
        		->add(new Zend_Acl_Resource('library:Languageswitch'), 'library');
        
        //then controller
        $this->add(new Zend_Acl_Resource('admin'))
        		->add(new Zend_Acl_Resource('admin:index'), 'admin')
        		->add(new Zend_Acl_Resource('admin:nguoidung'), 'admin')
        		->add(new Zend_Acl_Resource('admin:tintuc'), 'admin')
        		->add(new Zend_Acl_Resource('admin:chude'), 'admin')
        		->add(new Zend_Acl_Resource('admin:nhanvien'), 'admin')
        		->add(new Zend_Acl_Resource('admin:khachhang'), 'admin')
        		->add(new Zend_Acl_Resource('admin:phongban'), 'admin')
        		->add(new Zend_Acl_Resource('admin:chucvu'), 'admin')
        		->add(new Zend_Acl_Resource('admin:chinhanh'), 'admin')
        		->add(new Zend_Acl_Resource('admin:thechinh'), 'admin')        		
        		->add(new Zend_Acl_Resource('admin:loaivanban'), 'admin')
        		->add(new Zend_Acl_Resource('admin:nhomvanban'), 'admin')
        		->add(new Zend_Acl_Resource('admin:vanban'), 'admin')
        		->add(new Zend_Acl_Resource('admin:lienhe'), 'admin');
        
        
        
        $this->add(new Zend_Acl_Resource('default'))
        		->add(new Zend_Acl_Resource('default:authentication'), 'default')
        		->add(new Zend_Acl_Resource('default:nguoidung'), 'default')
        		->add(new Zend_Acl_Resource('default:index'), 'default')
        		->add(new Zend_Acl_Resource('default:error'), 'default')
        		->add(new Zend_Acl_Resource('default:tintuc'), 'default')
        		->add(new Zend_Acl_Resource('default:vanban'), 'default')
        		->add(new Zend_Acl_Resource('default:lienhe'), 'default')
        		->add(new Zend_Acl_Resource('default:thechinh'), 'default');
        
        
        $this->allow('guests', 'default:index', array('index', 'gioithieu', 'tamnhin', 'hoatdong', 'tuonglai', 'kehoach', 'thuonghieu'));
        $this->allow('guests', 'default:tintuc','index');       
        $this->allow('guests', 'default:thechinh', array('dangkythe', 'gioithieuthe', 'huongdan'));
        $this->allow('guests', 'default:lienhe', 'them');
        $this->allow('guests', 'library:Languageswitch', 'switch');
        $this->allow('guests', 'default:authentication', 'register');
        $this->allow('guests', 'default:nguoidung','capnhat' );
        $this->allow('guests', 'default:tintuc','index' );
        $this->allow('guests', 'default:tintuc','xem');;
        
        $this->allow('guests', 'default:authentication','login' );
        $this->allow('guests', 'default:error', 'error');
        
        $this->deny('users', 'default:authentication', 'login');
        $this->deny('users', 'default:authentication', 'register');
        $this->allow('users', 'default:index', 'index');
        $this->allow('users', 'default:tintuc', 'them');
        $this->allow('users', 'default:vanban', 'index');
        $this->allow('users', 'default:vanban', 'chitiet');
        
        $this->allow('users', 'default:authentication', 'logout');
       
        $this->allow('admins', 'admin:index', 'index');
        $this->allow('admins', 'admin:vanban', array( 'index','them', 'capnhat', 'xoa', 'chitiet'));
        $this->allow('admins', 'admin:loaivanban', array( 'index','them', 'capnhat', 'xoa'));
        $this->allow('admins', 'admin:nhomvanban', array( 'index','them', 'capnhat', 'xoa'));
        $this->allow('admins', 'admin:tintuc', array( 'index','them', 'capnhat', 'xoa', 'xem'));
        $this->allow('admins', 'admin:chude', array( 'index','them', 'capnhat', 'xoa'));
        $this->allow('admins', 'admin:nhanvien', array( 'index','them', 'capnhat', 'xoa'));
        $this->allow('admins', 'admin:khachhang', array( 'index','them', 'capnhat', 'xoa'));
        $this->allow('admins', 'admin:chinhanh', array( 'index','them', 'capnhat', 'xoa'));
        $this->allow('admins', 'admin:phongban', array( 'index','them', 'capnhat', 'xoa'));
        $this->allow('admins', 'admin:chucvu', array( 'index','them', 'capnhat', 'xoa'));
        $this->allow('admins', 'admin:thechinh', array( 'index','them', 'capnhat', 'xoa', 'nhan', 'xemkhachhang'));
        $this->allow('admins', 'admin:nguoidung', array( 'index','them', 'capnhat', 'xoa', 'list'));
        $this->allow('admins', 'admin:lienhe', array( 'index','them', 'capnhat', 'xoa'));
        
    }
    
    public function setDynamicPermissions(){
    	$this->addResource('comment');
    	$this->allow('users', 'comment', 'edit', new Library_Model_CommentAssetion());
    }
}
